﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BLL.ComplexClasses;
using DAL;
using App_Log;
using App_Utils; 
namespace BLL
{
    public class BL_Category
    {
        public static Category SaveRecord(Category objCategory)
        {
            try
            {
                clsLog.logMsg("Category", "SaveRecord", "Started");
                DAL.ithubEntities db = new ithubEntities();
                var query = (from q in db.tblCategories where q.category_id == objCategory.category_id select q).SingleOrDefault();

                if (query != null)
                {
                    query = (tblCategory)clsUtils.ConvertToObject(objCategory, new tblCategory());
                    db.SaveChanges();
                }
                else
                {
                    tblCategory _objtblCategory = new tblCategory();
                    _objtblCategory = (tblCategory)clsUtils.ConvertToObject(objCategory, new tblCategory());
                    db.tblCategories.Add(_objtblCategory);
                    db.SaveChanges();
                    objCategory = (Category)clsUtils.ConvertToObject(_objtblCategory, objCategory);
                }
            }
            catch (Exception ex)
            {
                clsLog.logError("Category", "SaveRecord", ex.Message);
            }
            return objCategory;
        }
    }
}
